package com.business_clean.viewmodel.request

import androidx.lifecycle.MutableLiveData
import com.business_clean.app.App
import com.business_clean.app.config.Constant.PAGE_SIZE
import com.business_clean.app.network.NetUrl
import com.business_clean.data.mode.custom.CompanyBaseEntity
import com.business_clean.data.mode.job.JobEntity
import com.business_clean.data.mode.project.ProjectCompanyDetailEntity
import com.business_clean.data.mode.project.ProjectManager
import me.hgj.mvvmhelper.base.BaseViewModel
import me.hgj.mvvmhelper.ext.rxHttpRequest
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

/**
 * 获取项目的
 */
class ProjectManagerViewModel : BaseViewModel() {

    var projectManger = MutableLiveData<ProjectManager>()

    var projectState = MutableLiveData<CompanyBaseEntity>()

    var jobManger = MutableLiveData<JobEntity>()

    var projectCompanyDetailEntity = MutableLiveData<ProjectCompanyDetailEntity>()


    fun getProjectMangerList(page: Int, custom_uuid: String) {
        rxHttpRequest {
            onRequest = {
                projectManger.value = RxHttp.get(NetUrl.GET_PROJECT_MANGER_LIST)
                    .add("page", page)
                    .add("size", PAGE_SIZE)
                    .add("custom_uuid", custom_uuid)
                    .toResponse<ProjectManager>().await()
            }
        }
    }


    /**
     * 对项目进行添加
     */
    fun saveProject(hashMap: HashMap<String, String>) {
        rxHttpRequest {
            onRequest = {
                projectState.value = RxHttp.get(NetUrl.SAVE_COMPANY_PROJECT)
                    .addAll(hashMap)
                    .toResponse<CompanyBaseEntity>().await()
            }
        }
    }


    /**
     * 获取岗位的列表
     */
    fun getJobList() {
        rxHttpRequest {
            onRequest = {
                jobManger.value = RxHttp.get(NetUrl.JOB_LIST)
                    .add("page", "1")
                    .add("size", "20")
                    .toResponse<JobEntity>().await()
            }
        }
    }


    /**
     * 获取项目详情
     */
    fun requestProjectMangerDetails(project_uuid: String) {
        rxHttpRequest {
            onRequest = {
                projectCompanyDetailEntity.value = RxHttp.get(NetUrl.GET_PROJECT_MANGER_DETAIL)
                    .add("project_uuid", project_uuid)
                    .toResponse<ProjectCompanyDetailEntity>().await()
            }
        }
    }


}